package com.oocl.venus.utils;

import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;

public class BeanFactory {
	
	private static final String beanPath = "bean.properties";
	private static Configuration config;
	
	static{
		try {
			config = new PropertiesConfiguration(beanPath);
		} catch (ConfigurationException e) {
			System.out.println(("Cannot find the beanFactory properties."));
			e.printStackTrace();
		}
	}
	
	public <T>T getInstance(String beanName) throws ClassNotFoundException, InstantiationException, IllegalAccessException{
		
		@SuppressWarnings("unchecked")
		T t = (T) Class.forName(config.getString(beanName)).newInstance();	
		return t;
	}

}
